<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" Theme="Default" 
    EnableTheming="true" CodeFile="SearchBooks.aspx.cs" Inherits="SearchBooks" 
    Title="Dr. Yurttas' Office Library &mdash; Search" %>
<asp:Content ID="ContentAdmin" ContentPlaceHolderID="MasterContentAdmin" Runat="Server">
    <asp:LoginView ID="LoginViewAdmin" runat="server">
        <RoleGroups>
            <asp:RoleGroup Roles="admin">
                <ContentTemplate>
                    <table border="0">
                        <tr>
                            <td style="width: 100px;">
                                <asp:Label ID="searchLabel" runat="server" Text="Search Criteria:"></asp:Label>
                            </td>
                            <td style="width: 300px;">
                                <asp:TextBox Width="300px" AutoPostBack="false" ID="searchKey" runat="server"></asp:TextBox>
                            </td>
                            <td style="width: 10px;">
                                &nbsp;
                            </td>
                            <td style="width: 100px;">
                                <!-- Hack to get default submit behavior in IE -->
                                <input type="text" style="VISIBILITY: hidden;POSITION: absolute" />
                                <asp:Button ID="searchButtonAdmin" OnClick="searchButtonAdmin_Click" 
                                    UseSubmitBehavior="true" Text="Go" runat="server" />
                            </td>
                        </tr>
                    </table>
                    <br />
                    <asp:GridView Width="100%" ID="bookListViewAdmin" runat="server" AllowPaging="True" 
                        OnRowCommand="bookListViewAdmin_RowCommand" DataSourceID="SqlDataSource1"
                        AutoGenerateColumns="False" AutoGenerateEditButton="False" AutoGenerateDeleteButton="False" 
                        AllowSorting="True" DataKeyNames="bookid">
                        <Columns>
                            <asp:CommandField ControlStyle-Font-Size="0.8em" ControlStyle-Font-Names="Verdana" 
                                ControlStyle-BorderStyle="Solid" ControlStyle-BorderWidth="1px" 
                                ControlStyle-BorderColor="#CCCCCC" ControlStyle-ForeColor="#284775" 
                                ControlStyle-BackColor="#FFFBFF" ButtonType="Button" SelectText="Select" 
                                ShowSelectButton="true" />
                            <asp:BoundField DataField="bookid" HeaderText="ISBN" SortExpression="bookid" 
                            ReadOnly="True" InsertVisible="False" Visible="True" />
                            <asp:HyperLinkField DataTextField="title" 
                                DataNavigateUrlFormatString="http://www.amazon.com/gp/product/{0}" 
                                DataNavigateUrlFields="bookid" HeaderText="Title" SortExpression="title" />
                        </Columns>
                    </asp:GridView>
                    <br />
                    <asp:Label BackColor="#5D7B9D" CssClass="block" Font-Bold="True" ForeColor="White" 
                        Text="&nbsp;&nbsp;Details:" runat="server" ID="detailsLabel" Width="100%"></asp:Label>
                    <asp:DetailsView Width="100%" OnItemUpdating="dosomething" 
                        AutoGenerateEditButton="True" AutoGenerateDeleteButton="True" 
                        runat="server" ID="bookDetailsViewAdmin" DataSourceID="SqlDataSource2" DataKeyNames="bookid" 
                        AutoGenerateRows="false" OnLoad="bookDetailsViewAdmin_Load" >
                        <Fields>
                            <asp:BoundField HeaderStyle-Width="100px" DataField="bookid" HeaderText="ISBN" 
                                ReadOnly="True" InsertVisible="False" Visible="True" />
                            <asp:BoundField HeaderStyle-Width="100px" DataField="title" HeaderText="Title" />
                            <asp:BoundField HeaderStyle-Width="100px" DataField="author" HeaderText="Author" />
                            <asp:BoundField HeaderStyle-Width="100px" DataField="publisher" HeaderText="Publisher" />
                            <asp:BoundField HeaderStyle-Width="100px" DataField="language" HeaderText="Language" />
                            <asp:BoundField HeaderStyle-Width="100px" DataField="number" HeaderText="Number" />
                            <asp:BoundField HeaderStyle-Width="100px" DataField="requested" HeaderText="Requested" />
                        </Fields>
                    </asp:DetailsView>    
                    <asp:Label ForeColor="Red" Text="" runat="server" ID="detailsComplete" Width="100%"></asp:Label>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:sylib %>" ProviderName="System.Data.SqlClient"
                        SelectCommand="SELECT bookid, title, publisher, substring(title,0,25) AS shortTitle,
                            substring(author,0,10) as shortAuthor, author, substring(publisher,0,15) AS shortPublisher,
                            language, number, requested FROM [books] ORDER BY [author], [title], [publisher]" >
                    </asp:SqlDataSource>


<asp:Button ID="Button2" OnClick="Button2_Click" UseSubmitBehavior="true"
Text="Bind Detail" runat="server" />
<asp:TextBox AutoPostBack="false" ID="hiddenSearchKey" Visible="true" runat="server"></asp:TextBox>

                    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:sylib %>" ProviderName="System.Data.SqlClient"
                        UpdateCommand="UPDATE [books] SET [title] = @title, [author] = @author, 
                            [publisher] = @publisher, [language] = @language, [requested] = @requested, 
                            [number] = @number WHERE [bookid] = @bookid"
                        DeleteCommand="DELETE FROM [books] WHERE [bookid] = @bookid" 
                        
                        SelectCommand="SELECT * FROM books WHERE bookid = @bookid"
                        >
                        <SelectParameters>
                            <asp:ControlParameter Name="bookid" ControlID="hiddenSearchKey" PropertyName="Text" />
                        </SelectParameters>
                        <DeleteParameters>
                            <asp:Parameter Name="bookid" Type="String" />
                        </DeleteParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="bookid" Type="String" />
                            <asp:Parameter Name="title" Type="String" />
                            <asp:Parameter Name="author" Type="String" />
                            <asp:Parameter Name="publisher" Type="String" />
                            <asp:Parameter Name="language" Type="String" />
                            <asp:Parameter Name="status" Type="String" />
                            <asp:Parameter Name="number" Type="Int32" />
                        </UpdateParameters>
                    </asp:SqlDataSource>
                </ContentTemplate>
            </asp:RoleGroup>
        </RoleGroups>
    </asp:LoginView>
</asp:Content>
<asp:Content ID="ContentUser" ContentPlaceHolderID="MasterContentUser" Runat="Server">
    <asp:LoginView ID="LoginViewUser" runat="server">
        <RoleGroups>
            <asp:RoleGroup Roles="user">
                <ContentTemplate>
                    <table border="0">
                        <tr>
                            <td style="width: 100px;">
                                <asp:Label ID="searchLabel" runat="server" Text="Search Criteria:"></asp:Label>
                            </td>
                            <td style="width: 300px;">
                                <asp:TextBox Width="300px" ID="searchKey" runat="server"></asp:TextBox>
                            </td>
                            <td style="width: 10px;">
                                &nbsp;
                            </td>
                            <td style="width: 100px;">
                                <!-- Hack to get default submit behavior in IE -->
                                <input type="text" style="VISIBILITY: hidden;POSITION: absolute" />
                                <asp:Button ID="searchButton" OnClick="searchButton_Click" 
                                    UseSubmitBehavior="true" Text="Go" runat="server" />
                            </td>
                        </tr>
                    </table>
                    <br />
                    <asp:GridView Width="100%" ID="bookListView" runat="server" AllowPaging="True" 
                        OnRowCommand="bookListView_RowCommand" DataSourceID="SqlDataSource1"
                        AutoGenerateColumns="False" AutoGenerateEditButton="False" AutoGenerateDeleteButton="False" 
                        AllowSorting="True" DataKeyNames="bookid">
                        <Columns>
                            <asp:CommandField ControlStyle-Font-Size="0.8em" ControlStyle-Font-Names="Verdana" 
                                ControlStyle-BorderStyle="Solid" ControlStyle-BorderWidth="1px" 
                                ControlStyle-BorderColor="#CCCCCC" ControlStyle-ForeColor="#284775" 
                                ControlStyle-BackColor="#FFFBFF" ButtonType="Button" SelectText="Select" 
                                ShowSelectButton="true" />
                            <asp:BoundField DataField="bookid" HeaderText="ISBN" SortExpression="bookid" 
                            ReadOnly="True" InsertVisible="False" Visible="True" />
                            <asp:HyperLinkField DataTextField="title" 
                                DataNavigateUrlFormatString="http://www.amazon.com/gp/product/{0}" 
                                DataNavigateUrlFields="bookid" HeaderText="Title" SortExpression="title" />
                        </Columns>
                    </asp:GridView>
                    <br />
                    <asp:Label BackColor="#5D7B9D" CssClass="block" Font-Bold="True" ForeColor="White" 
                        Text="&nbsp;&nbsp;Details:" runat="server" ID="detailsLabel" Width="100%"></asp:Label>
                    <asp:DetailsView OnItemCommand="bookDetailsView_ItemCommand" Width="100%" 
                        runat="server" ID="bookDetailsView" DataSourceID="SqlDataSource2" DataKeyNames="bookid" 
                        AutoGenerateRows="false" >
                        <Fields>
                            <asp:BoundField HeaderStyle-Width="100px" DataField="bookid" HeaderText="ISBN" 
                                ReadOnly="True" InsertVisible="False" Visible="True" />
                            <asp:BoundField HeaderStyle-Width="100px" DataField="title" HeaderText="Title" />
                            <asp:BoundField HeaderStyle-Width="100px" DataField="author" HeaderText="Author" />
                            <asp:BoundField HeaderStyle-Width="100px" DataField="publisher" HeaderText="Publisher" />
                            <asp:BoundField HeaderStyle-Width="100px" DataField="language" HeaderText="Language" />
                            <asp:BoundField HeaderStyle-Width="100px" DataField="number" HeaderText="Number" />
                            <asp:BoundField HeaderStyle-Width="100px" DataField="requested" HeaderText="Requested" />
                            <asp:ButtonField ControlStyle-Font-Size="0.8em" ControlStyle-Font-Names="Verdana" 
                                ControlStyle-BorderStyle="Solid" ControlStyle-BorderWidth="1px" 
                                ControlStyle-BorderColor="#CCCCCC" ControlStyle-ForeColor="#284775" 
                                ControlStyle-BackColor="#FFFBFF" ButtonType="Button" HeaderText="" 
                                CommandName="Request" Text="Requst" />
                        </Fields>
                    </asp:DetailsView>    
                    <asp:Label ForeColor="Red" Text="" runat="server" ID="detailsComplete" Width="100%"></asp:Label>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:sylib %>"
                        SelectCommand="SELECT bookid, title, publisher, substring(title,0,25) AS shortTitle,
                            substring(author,0,10) as shortAuthor, author, substring(publisher,0,15) AS shortPublisher,
                            language, number, requested FROM [books] ORDER BY [author], [title], [publisher]" >
                    </asp:SqlDataSource>
                    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:sylib %>" >
                    </asp:SqlDataSource>
                </ContentTemplate>
            </asp:RoleGroup>
        </RoleGroups>
    </asp:LoginView>
</asp:Content>
<asp:Content ID="ContentAnonymous" ContentPlaceHolderID="MasterContentAnonymous" Runat="Server">
    <asp:LoginView ID="LoginViewAnonymous" runat="server">
        <AnonymousTemplate>
            Please register before using this service.
        </AnonymousTemplate>
    </asp:LoginView>
</asp:Content>